/**
 * AlertMessage.java
 *
 * @author liujie
 * 
 * @date 2011-4-7
 * 
 * Copyright 2011 NetEase. All rights reserved. 
 */
package com.japher.hackson.utils;


import java.lang.ref.WeakReference;

import android.content.Context;
import android.graphics.Color;
import android.view.ViewGroup.LayoutParams;
import android.widget.TextView;
import android.widget.Toast;

import com.japher.hackson.R;



public class AlertMessage
{
	public static boolean customed = false;
	
    private static WeakReference<TextView> view;
    
    public static void show(Context context, String message,boolean isLong)
    {
    	int type = isLong ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT; 
    	if(customed)
    	{
    		show(context,message,type);
    	}
    	else
    	{
    		Toast.makeText(context, message, type).show();
    	}
    	
    }
    
    public static void show(Context context, String message)
    {
    	show(context, message,true);
    }
    
    public static void show(Context context, String message,int duration)
    {
        try
        {
            TextView textView;
            if(view == null || view.get() == null)
            {
                textView = new TextView(context);
                int paddingTop = Tools.getPixelByDip(context,8);
                int paddingLeft = Tools.getPixelByDip(context,15);
                textView.setPadding(paddingLeft, paddingTop, paddingLeft, paddingTop);
                textView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
                //textView.setBackgroundResource(R.color.alert_message_bg);
                textView.setMinHeight(Tools.getPixelByDip(context, 30));
                textView.setText(message);
                textView.setTextColor(context.getResources().getColor(Color.WHITE));
                view = new WeakReference<TextView>(textView);
            }
            else
            {
                textView = view.get();
            }
            Toast toast = new Toast(context);
            textView.setText(message);
            toast.setView(textView);
            toast.setDuration(duration);
            toast.show();
        }
        catch(Exception e)
        {
        }
    }
    
}
